home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’92 / Not / Not.a next >
Encoding:
Text File  |  1992-06-19  |  8.9 KB  |  396 lines  |  [TEXT/MPS ]

  1. ; Not!
  2. ;
  3. ; A highly sophisticated hack — Not!
  4. ;
  5. ; by Darin Adler and Nevin Liber
  6. ; extensive help from Greg Marriott, Jim Reekes, Philip Nguyen and Jeff Miller — Not!
  7. ; idea suggested by Waldemar Horwat
  8. ;
  9. ; The idea is to notice modal dialogs that contain some negative message.
  10. ; If they also contain a button with the word OK, it is changed to Not,
  11. ; and a sound is played when the button is hit ("Not!"). Also, the negatives
  12. ; are all changed to positives.
  13. ;
  14. ; Highlights
  15. ;
  16. ;    all programming done on the night of the 1992 MacHack hack contest
  17. ;    all programming done in under 2 hours
  18. ;    3 patches
  19. ;
  20. ; Ideas
  21. ;
  22. ;    handle Yes/No and Save/Don’t Save
  23. ;    do better checking of the grammar of the sentence
  24. ;    play QuickTime movie of Wayne’s World clip instead of just sound
  25. ;    add help balloons
  26. ;    rewrite in C
  27. ;    rewrite in C++
  28. ;    build into Macintosh system software
  29. ;    get a life
  30. ;    add ! mark after Not
  31.  
  32.                 INCLUDE    'QuickEqu.a'
  33.                 INCLUDE    'SysEqu.a'
  34.                 INCLUDE    'ToolEqu.a'
  35.                 INCLUDE    'Traps.a'
  36.  
  37. DrawDialogTrap        EQU        $A981
  38. DrawTextTrap        EQU        $A885
  39. ModalDialogTrap        EQU        $A991
  40.  
  41. ;---------------------------------------------------------------------------------
  42. ;
  43. ;    MAIN
  44. ;    Install our patches
  45. ;
  46. ;---------------------------------------------------------------------------------
  47.  
  48. PatchIt            MAIN    EXPORT
  49.                 IMPORT    PatchStart, PatchEnd
  50.                 IMPORT    OldDrawDialogTrapAddress,NewDrawDialogTrapCode
  51.                 IMPORT    OldDrawTextTrapAddress,NewDrawTextTrapCode
  52.                 IMPORT    OldModalDialogTrapAddress,NewModalDialogTrapCode
  53.                 IMPORT    DetachedSoundResource
  54.  
  55. shiftByte        EQU        7                            ; byte and
  56. shiftBit        EQU        0                            ;  bit offset in key map for shift key
  57.  
  58.                 CLR.B    -(SP)                        ; boolean result for Button
  59.                 _Button
  60.                 MOVE.B    (SP)+, D0                    ; get and test result
  61.                 BNE        ExitWithFailure                ; get outta town if button is down...
  62.                 PEA        myKeys                        ; my copy of the key map
  63.                 _GetKeys
  64.                 LEA        myKeys, A0
  65.                 BTST    #shiftBit, shiftByte(A0)    ; check the shift key
  66.                 BNE        ExitWithFailure                ; get outta town if shift key is down...
  67.     
  68. CopyPatchCode
  69.                 LEA        PatchEnd, A2                ; use the end and the beginning
  70.                 LEA        PatchStart, A1                ;  of the patch to calculate its
  71.                 SUBA.L    A1, A2                        ;  size
  72.                 MOVE.L    A2, D0
  73.                 _NewPtr    sys                          ; allocate space for the patch
  74.                 BEQ.S    PatchOK                        ; if we succeed, copy the patch into sysheap
  75.                 BRA        ExitWithFailure                ; otherwise, die
  76.  
  77. PatchOK
  78.                 EXG    A0, A1                            ; A1 has source, A0 has dest, but _BlockMove needs them swapped
  79.                 MOVE.L    A2, D0                        ; size of block from calculation goes in D0
  80.                 _BlockMove                            ; IM says this can't fail (hardy har har...)
  81.                 
  82.                 MOVE.W    #DrawDialogTrap,D0            ; get old trap address and put it in the patch
  83.                 _GetTrapAddress                        ;  so it can call the real trap code
  84.                 LEA        OldDrawDialogTrapAddress-PatchStart(A1), A2
  85.                 MOVE.L    A0, (A2)
  86.                                 
  87.                 LEA        NewDrawDialogTrapCode-PatchStart(A1), a0
  88.                 move.l a0, d0
  89.                 _StripAddress
  90.                 move.l d0, a0
  91.                 MOVE.W    #DrawDialogTrap, D0
  92.                 _SetTrapAddress                        ; load up our address in the trap table
  93.                 
  94.                 MOVE.W    #DrawTextTrap,D0            ; get old trap address and put it in the patch
  95.                 _GetTrapAddress                        ;  so it can call the real trap code
  96.                 LEA        OldDrawTextTrapAddress-PatchStart(A1), A2
  97.                 MOVE.L    A0, (A2)
  98.                                 
  99.                 LEA        NewDrawTextTrapCode-PatchStart(A1), a0
  100.                 move.l a0, d0
  101.                 _StripAddress
  102.                 move.l d0, a0
  103.                 MOVE.W    #DrawTextTrap, D0
  104.                 _SetTrapAddress                        ; load up our address in the trap table
  105.                 
  106.                 MOVE.W    #ModalDialogTrap,D0            ; get old trap address and put it in the patch
  107.                 _GetTrapAddress                        ;  so it can call the real trap code
  108.                 LEA        OldModalDialogTrapAddress-PatchStart(A1), A2
  109.                 MOVE.L    A0, (A2)
  110.                                 
  111.                 LEA        NewModalDialogTrapCode-PatchStart(A1), a0
  112.                 move.l a0, d0
  113.                 _StripAddress
  114.                 move.l d0, a0
  115.                 MOVE.W    #ModalDialogTrap, D0
  116.                 _SetTrapAddress                        ; load up our address in the trap table
  117.  
  118.                 _GetZone
  119.                 move.l    a0,-(sp)
  120.                 move.l    SysZone,a0
  121.                 _SetZone
  122.                 lea        DetachedSoundResource-PatchStart(a1),a2
  123.                 subq    #4,sp
  124.                 move.l    #'snd ',-(sp)
  125.                 move.w    #1,-(sp)
  126.                 _Get1IxResource
  127.                 move.l    (sp),(a2)
  128.                 move.l    (sp),a0
  129.                 _HNoPurge
  130.                 _DetachResource
  131.                 move.l    (sp)+,a0
  132.                 _SetZone
  133.  
  134. ExitWithSuccess
  135. ExitWithFailure
  136.                 
  137. AllDone
  138.                 RTS                                    ; bye bye
  139.             
  140. myKeys
  141.                 DCB.B    128/8, 0                    ; KeyMap structure for GetKeys
  142.  
  143.                 ENDMAIN
  144.  
  145. ;---------------------------------------------------------------------------------
  146. ;
  147. ;    PROC PatchStart
  148. ;
  149. ;    Just a place holder for the patch size calculation.
  150. ;
  151. ;---------------------------------------------------------------------------------
  152.  
  153. PatchStart        PROC    EXPORT
  154.                 ENDP
  155.  
  156. ;---------------------------------------------------------------------------------
  157. ;
  158. ;    NewDrawDialogTrapCode goes here
  159. ;
  160. ;---------------------------------------------------------------------------------
  161. NewDrawDialogTrapCode        PROC    EXPORT
  162.                 EXPORT    OldDrawDialogTrapAddress
  163.                 IMPORT    InsideDrawDialog
  164.  
  165.                 lea        InsideDrawDialog,a0
  166.                 st        (a0)
  167.  
  168.                 move.l    4(sp),-(sp)
  169.                 jsr        $12345678
  170. OldDrawDialogTrapAddress    EQU        *-4
  171.  
  172.                 lea        InsideDrawDialog,a0
  173.                 clr.b    (a0)
  174.  
  175.                 move.l    (sp)+,(sp)
  176.                 rts
  177.                 
  178.                 ENDP
  179.                                 
  180. ;---------------------------------------------------------------------------------
  181. ;
  182. ;    NewDrawTextTrapCode goes here
  183. ;
  184. ;---------------------------------------------------------------------------------
  185. NewDrawTextTrapCode        PROC    EXPORT
  186.                 EXPORT    OldDrawTextTrapAddress
  187.                 EXPORT    InsideDrawDialog
  188.  
  189. ;patch DrawText
  190. ;if inside DrawDialog and text drawn contains "not " or "n’t"
  191. ;    remove the matched string
  192. ;    change title of control from "OK" to "Not"
  193.  
  194.                 lea        InsideDrawDialog,a0
  195.                 tst.b    (a0)
  196.                 beq        DoOld
  197.  
  198.                 ; check text for "not " or "n’t"
  199.                 move.l    8(sp),a0
  200.                 add.w    6(sp),a0
  201.                 moveq    #0,d0
  202.                 move.w    4(sp),d0
  203.                 _PtrToHand
  204.                 bne        DoOld
  205.  
  206.                 movem.l    a2/a3/d3,-(sp)
  207.                 move.l    a0,-(sp)
  208.                 moveq    #0,d3
  209.  
  210.                 lea        NotStrings,a2
  211. NextString
  212.                 tst.b    (a2)
  213.                 beq.s    DoneStrings
  214.                 move.l    a2,a3
  215. Repeat
  216.                 move.l    (sp),a0
  217.                 subq    #4,sp
  218.                 move.l    a0,-(sp)
  219.                 clr.l    -(sp)
  220.                 moveq    #0,d0
  221.                 move.b    (a2)+,d0
  222.                 move.l    a2,-(sp)
  223.                 move.l    d0,-(sp)
  224.                 add.l    d0,a2
  225.                 moveq    #0,d0
  226.                 move.b    (a2)+,d0
  227.                 move.l    a2,-(sp)
  228.                 move.l    d0,-(sp)
  229.                 add.l    d0,a2
  230.                 _Munger
  231.                 tst.l    (sp)+
  232.                 bmi.s    NextString
  233.                 moveq    #1,d3
  234.                 move.l    a3,a2
  235.                 bra.s    Repeat
  236.  
  237. DoneStrings
  238.                 tst.l    d3
  239.                 beq.s    Boredom
  240.  
  241. Excitement
  242.                 subq    #4,sp
  243.                 _FrontWindow
  244.                 move.l    (sp)+,a0
  245.                 move.l    wControlList(a0),a2
  246.  
  247. TryNext
  248.                 move.l    a2,d0
  249.                 beq.s    Boredom
  250.  
  251.                 move.l    (a2),a0
  252.                 moveq    #0,d0
  253.                 lea        contrlTitle(a0),a0
  254.                 move.b    (a0)+,d0
  255.                 swap    d0
  256.                 lea        #'OK',a1
  257.                 move.b    (a1)+,d0
  258.                 _CmpString
  259.                 beq.s    SuperThrills
  260.                 move.l    (a2),a0
  261.                 moveq    #0,d0
  262.                 lea        contrlTitle(a0),a0
  263.                 move.b    (a0)+,d0
  264.                 swap    d0
  265.                 lea        #'Not',a1
  266.                 move.b    (a1)+,d0
  267.                 _CmpString
  268.                 beq.s    SuperThrills2
  269.                 move.l    (a2),a0
  270.                 move.l    nextControl(a0),a2
  271.                 bra.s    TryNext
  272.  
  273. SuperThrills
  274.                 move.l    a2,-(sp)
  275.                 pea        #'Not'
  276.                 _SetCTitle
  277.  
  278. SuperThrills2
  279.                 move.l    (sp),a0
  280.                 _HLock
  281.                 move.l    (a0),-(sp)
  282.                 clr.w    -(sp)
  283.                 _GetHandleSize
  284.                 move.w    d0,-(sp)
  285.                 bsr.s    DoOld
  286.  
  287.                 move.l    (sp)+,a0
  288.                 _DisposeHandle
  289.                 movem.l    (sp)+,a2/a3/d3
  290.  
  291.                 move.l    (sp)+,a0
  292.                 addq    #8,sp
  293.                 jmp        (a0)
  294.  
  295. Boredom
  296.                 move.l    (sp)+,a0
  297.                 _DisposeHandle
  298.                 movem.l    (sp)+,a2/a3/d3
  299.  
  300. DoOld
  301.                 jmp        $12345678
  302. OldDrawTextTrapAddress    EQU        *-4
  303.  
  304. InsideDrawDialog    dc.b    0
  305.                 align
  306.  
  307. NotStrings
  308.                     dc.b    'cannot','can'
  309.                     dc.b    'not ',''
  310.                     dc.b    'won’t','will'
  311.                     dc.b    5,('w'),('o'),('n'),39,('t'),'will'
  312.                     dc.b    'can’t','can'
  313.                     dc.b    5,('c'),('a'),('n'),39,('t'),'can'
  314.                     dc.b    'n’t',''
  315.                     dc.b    3,('n'),39,('t'),''
  316.                     dc.b    0
  317.  
  318.                 ENDP
  319.                                 
  320. ;---------------------------------------------------------------------------------
  321. ;
  322. ;    NewModalDialogTrapCode goes here
  323. ;
  324. ;---------------------------------------------------------------------------------
  325. NewModalDialogTrapCode        PROC    EXPORT
  326.                 EXPORT    OldModalDialogTrapAddress,DetachedSoundResource
  327.  
  328. ;patch ModalDialog
  329. ;if chosen item is a button with title "Not"
  330. ;    play sound "Not"
  331.  
  332.                 move.l    8(sp),-(sp)
  333.                 move.l    8(sp),-(sp)
  334.  
  335.                 jsr        $12345678
  336. OldModalDialogTrapAddress    EQU        *-4
  337.  
  338.                 link    a6,#-300
  339.  
  340.                 subq    #4,sp
  341.                 _FrontWindow
  342.                 move.l    8(a6),a0
  343.                 move.w    (a0),-(sp)
  344.                 pea        -2(a6)
  345.                 pea        -6(a6)
  346.                 pea        -14(a6)
  347.                 _GetDItem
  348.                 move.w    -2(a6),d0        ; get item type
  349.                 cmp.w    #4,d0
  350.                 beq.s    GotButton
  351.                 cmp.w    #132,d0
  352.                 bne.s    Return
  353.  
  354. GotButton
  355.                 move.l    -6(a6),-(sp)
  356.                 pea        -300(a6)
  357.                 _GetCTitle
  358.  
  359.                 moveq    #0,d0
  360.                 lea.l    -300(a6),a0
  361.                 move.b    (a0)+,d0
  362.                 swap    d0
  363.                 lea        #'Not',a1
  364.                 move.b    (a1)+,d0
  365.                 _CmpString
  366.                 bne.s    Return
  367.  
  368.                 subq    #2,sp
  369.                 clr.l    -(sp)
  370.                 move.l    DetachedSoundResource,-(sp)
  371.                 clr.b    -(sp)
  372.                 _SndPlay
  373.  
  374. Return
  375.                 unlk    a6
  376.  
  377.                 move.l    (sp)+,a0
  378.                 addq    #8,sp
  379.                 jmp        (a0)
  380.  
  381. DetachedSoundResource    dc.l    0
  382.  
  383.                 ENDP
  384.                                 
  385. ;---------------------------------------------------------------------------------
  386. ;
  387. ;    PROC PatchEnd
  388. ;
  389. ;    Just a place holder for the patch size calculation.
  390. ;
  391. ;---------------------------------------------------------------------------------
  392.  
  393. PatchEnd        PROC    EXPORT
  394.                 ENDP
  395.  
  396.                 END